unit Class_BILL_FL;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TBILLFL=class(TUniEngine)
  private
    FUNITLINK: string;
    FBILLIDEX: Integer;
    FBILLFLID: Integer;
    FPRODIDEX: Integer;
    FPRODNUMB: Integer;
    FPRODMONY: Extended;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property UNITLINK: string read FUNITLINK write FUNITLINK;
    property BILLIDEX: Integer read FBILLIDEX write FBILLIDEX;
    property BILLFLID: Integer read FBILLFLID write FBILLFLID;
    property PRODIDEX: Integer read FPRODIDEX write FPRODIDEX;
    property PRODNUMB: Integer read FPRODNUMB write FPRODNUMB;
    property PRODMONY: Extended read FPRODMONY write FPRODMONY;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(ABILLFL:TBILLFL):TBILLFL;overload;        
    class procedure CopyIt(ABILLFL:TBILLFL;var Result:TBILLFL);overload;       
  end;

implementation

{ TBILLFL }
procedure TBILLFL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('BILL_IDEX').Value := BILLIDEX;
        ParamByName('BILL_FLID').Value := BILLFLID;
        ParamByName('PROD_IDEX').Value := PRODIDEX;
        ParamByName('PROD_NUMB').Value := PRODNUMB;
        ParamByName('PROD_MONY').Value := PRODMONY; 
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('BILL_IDEX').Value := BILLIDEX;
        ParamByName('BILL_FLID').Value := BILLFLID;
        ParamByName('PROD_IDEX').Value := PRODIDEX;
        ParamByName('PROD_NUMB').Value := PRODNUMB;
        ParamByName('PROD_MONY').Value := PRODMONY; 
      end;  
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('BILL_IDEX').Value := BILLIDEX;
        ParamByName('BILL_FLID').Value := BILLFLID;
 
      end;  
    end;
  end;
end;

function TBILLFL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_BILL_FL',['UNIT_LINK',UNITLINK,'BILL_IDEX',BILLIDEX,'BILL_FLID',BILLFLID],AUniConnection);
end;

function TBILLFL.GetNextIdex: Integer;
begin

end;

function TBILLFL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TBILLFL.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_BILL_FL WHERE   UNIT_LINK=:UNIT_LINK AND BILL_IDEX=:BILL_IDEX AND BILL_FLID=:BILL_FLID';
end;

function TBILLFL.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_BILL_FL'
         +'    ( UNIT_LINK, BILL_IDEX, BILL_FLID, PROD_IDEX, PROD_NUMB'
         +'    , PROD_MONY)'
         +'    VALUES'
         +'    (:UNIT_LINK,:BILL_IDEX,:BILL_FLID,:PROD_IDEX,:PROD_NUMB'
         +'    ,:PROD_MONY)';
end;

function TBILLFL.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%D',[UNITLINK,BILLIDEX,BILLFLID]);
end;

function TBILLFL.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_BILL_FL SET'
         +'    PROD_IDEX=:PROD_IDEX,'
         +'    PROD_NUMB=:PROD_NUMB,'
         +'    PROD_MONY=:PROD_MONY'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   BILL_IDEX=:BILL_IDEX'
         +'    AND   BILL_FLID=:BILL_FLID';
end;

constructor TBILLFL.Create;
begin

end;

destructor TBILLFL.Destroy;
begin

  inherited;
end;

class function TBILLFL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TBILLFL.Create;
  with TBILLFL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    BILLIDEX:=AUniQuery.FieldByName('BILL_IDEX').AsInteger;
    BILLFLID:=AUniQuery.FieldByName('BILL_FLID').AsInteger;
    PRODIDEX:=AUniQuery.FieldByName('PROD_IDEX').AsInteger;
    PRODNUMB:=AUniQuery.FieldByName('PROD_NUMB').AsInteger;
    PRODMONY:=AUniQuery.FieldByName('PROD_MONY').AsFloat;
  end;  
end;

class procedure TBILLFL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TBILLFL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    BILLIDEX:=AUniQuery.FieldByName('BILL_IDEX').AsInteger;
    BILLFLID:=AUniQuery.FieldByName('BILL_FLID').AsInteger;
    PRODIDEX:=AUniQuery.FieldByName('PROD_IDEX').AsInteger;
    PRODNUMB:=AUniQuery.FieldByName('PROD_NUMB').AsInteger;
    PRODMONY:=AUniQuery.FieldByName('PROD_MONY').AsFloat;
  end;  
end;

class function  TBILLFL.CopyIt(ABILLFL: TBILLFL): TBILLFL;
begin
  Result:=TBILLFL.Create;
  TBILLFL.CopyIt(ABILLFL,Result)
end;

class procedure TBILLFL.CopyIt(ABILLFL:TBILLFL;var Result:TBILLFL);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=ABILLFL.UNITLINK;
  Result.BILLIDEX:=ABILLFL.BILLIDEX;
  Result.BILLFLID:=ABILLFL.BILLFLID;
  Result.PRODIDEX:=ABILLFL.PRODIDEX;
  Result.PRODNUMB:=ABILLFL.PRODNUMB;
  Result.PRODMONY:=ABILLFL.PRODMONY;
end;

end.

